package com.mall.server.controller.pms;


import com.mall.model.domain.PmsBrand;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.pms.PmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/brand")
public class PmsBrandController {

    @Autowired
    private PmsBrandService brandService;

    @PostMapping("/create")
    public CommonResult createBrand(@RequestBody PmsBrand pmsBrand){
        brandService.saveBrand(pmsBrand);
        return CommonResult.success(null);
    }

    @PostMapping("/delete/batch")
    public CommonResult deleteBrandIds(@RequestParam Long[] ids ){
        brandService.deleteBrandIds(ids);
        return CommonResult.success(null);
    }

    @GetMapping("/delete/{id}")
    public CommonResult deleteBrandId(@PathVariable("id") Long id ){
        brandService.deleteBrandId(id);
        return CommonResult.success(null);
    }

    @GetMapping("/list")
    public CommonResult queryList(String keyword,
                                @RequestParam(defaultValue = "1")Integer pageNum,
                                @RequestParam(defaultValue = "10")Integer pageSize){
        CommonPage<PmsBrand> commonResult=brandService.queryList(keyword,pageNum,pageSize);

        return CommonResult.success(commonResult);
    }


    @GetMapping("/listAll")
    public CommonResult listAll(){
        List<PmsBrand> list=brandService.listAll();
        return CommonResult.success(list);
    }

    @PostMapping("/update/factoryStatus")
    public CommonResult updateFactoryStatus(Integer factoryStatus,Long[] ids){
        brandService.updateFactoryStatus(factoryStatus,ids);
        return CommonResult.success(null);
    }

    @PostMapping("/update/showStatus")
    public CommonResult updateShowStatus(Integer showStatus,Long[] ids){
        brandService.updateShowStatus(showStatus,ids);
        return CommonResult.success(null);
    }

    @PostMapping("/update/{id}")
    public CommonResult updateBrand(@PathVariable("id") Integer id,@RequestBody PmsBrand brand){
        brandService.updateBrand(id,brand);
        return CommonResult.success(null);
    }

    @GetMapping("/{id}")
    public CommonResult findBrandByid(@PathVariable Integer id){
        PmsBrand brand=brandService.findBrandByid(id);
        return CommonResult.success(brand);
    }

}
